﻿using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WebApplication1.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class FundController : ControllerBase
    {
        public IFreeSql _freeSql;
        public FundController(IFreeSql freeSql)
        {
            _freeSql=freeSql;
        }
        // GET: api/<FundController>
        [HttpGet]
        public long Get()
        {
            return 1;
        }

        // GET api/<FundController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        [HttpPost("getFundList")]       
        public ReturnMsg GetFundList([FromBody] object f)
        {
            List<FundInfo> result = _freeSql.Select<FundInfo>().ToList();         
            var data = new ReturnMsg(new DataInfo() { total=result.Count,data=result});
            return data;
        }

        [HttpPost("update")]
        public ReturnMsg UpdateFund([FromBody] FundInfo fundInfo)
        {
            int  result= _freeSql.Update<FundInfo>(fundInfo).Where(x=>x.Id==fundInfo.Id).ExecuteAffrows();
            var data = new ReturnMsg(result);
            return data;
        }

        // POST api/<FundController>  添加
        //[HttpPost]
        //public int Post([FromBody] FundInfo fundInfo)
        //{     
        //   var result = _freeSql.Insert(fundInfo).ExecuteAffrows();
        //    return result;
        //}

        // PUT api/<FundController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<FundController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }

    }
}
